<template>
   <div>
      <el-card>
         <el-tag type="success" class="item" v-for="type in typeList" :key="type.id">{{ type.title }}</el-tag>
      </el-card>
      <el-form>
         <el-form-item label="类型: ">
            <el-input v-model="title" placeholder="请不要重复添加"></el-input>
         </el-form-item>
         <el-form-item>
            <el-button type="primary" plain @click="postType">添加</el-button>
         </el-form-item>
      </el-form>
   </div>
</template>

<script>
   export default {
      name: "TypeAdd",
      data() {
         return {
            title: '',
            typeList: [],
         }
      },
      created() {
         this.$axios({
            url: 'adminapp/type/',
         }).then(resp => {
            this.typeList = resp.data
         })
      },
      methods: {
         postType() {
            this.$axios({
               url: 'adminapp/type/',
               method: 'POST',
               data: {
                  title: this.title
               }
            }).then(resp => {
               if (resp.data.code == 200) {
                  alert(resp.data.msg);
                  this.$router.go(0)
               } else {
                  alert('NO');
                  console.log(resp.data.msg)
               }
            })
         }
      },
      computed: {},
      filters: {},
      watch: {},
   }
</script>

<style scoped>
  .item {
     margin-left: 10px;
     font-size: 16px;
  }
</style>
